package com.easylinkin.linkappapi.grid.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.BaseController;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.grid.models.query.GridHiddenDangerQuery;
import com.easylinkin.linkappapi.grid.models.vo.GridHiddenDangerInfoVO;
import com.easylinkin.linkappapi.grid.models.vo.GridHiddenDangerListVO;
import com.easylinkin.linkappapi.grid.service.IGridHiddenDangerService;
import com.easylinkin.linkappapi.lobar.entity.emp.EmpUserBaseQuery;
import com.easylinkin.linkappapi.lobar.entity.vo.EmpUserBaseVO;
import com.easylinkin.linkappapi.openapi.service.EmpUserBaseService;
import com.easylinkin.linkappapi.safe.entity.HiddenDanger;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Setter;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * 网格隐患
 *
 * @author kyj
 * @date 2024/5/28 16:12
 */
@Api(tags = "网格隐患")
@Setter(onMethod_ = @Resource)
@RestController
@RequestMapping("/grid/gridHiddenDanger")
public class GridHiddenDangerController extends BaseController {

    private IGridHiddenDangerService gridHiddenDangerService;
    private EmpUserBaseService empUserBaseService;

    /**
     * 分页列表查询
     *
     * @param requestModel
     * @return
     */
    @ApiOperation(value = "分页列表查询", notes = "分页列表查询")
    @PostMapping(value = "/listPage")
    public RestMessage queryPageList(@RequestBody RequestModel<GridHiddenDangerQuery> requestModel) {
        this.setOperator(requestModel.getCustomQueryParams());
        IPage<GridHiddenDangerListVO> data = gridHiddenDangerService.pageList(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder().data(data).build();
    }

    /**
     * 保存
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "保存", notes = "保存")
    @PostMapping(value = "/save")
    public RestMessage save(@RequestBody HiddenDanger dto) {
        gridHiddenDangerService.saveOne(dto);
        return RestBuilders.successBuilder().message("保存成功").build();
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping(value = "/queryById")
    public RestMessage queryById(@RequestParam("id") Serializable id) {
        GridHiddenDangerInfoVO data = gridHiddenDangerService.getOneById(id);
        return RestBuilders.successBuilder().data(data).build();
    }

    /**
     * 验证身份
     *
     * @param query
     * @return EmpUserBaseVO
     * @author kyj
     * @date 2024/5/31 11:19
     */
    @ApiOperation(value = "验证身份", notes = "验证身份")
    @PostMapping(value = "/checkUser")
    public RestMessage checkUser(@RequestBody EmpUserBaseQuery query) {
        EmpUserBaseVO data = empUserBaseService.getExistByQuery(query);
        return RestBuilders.successBuilder().data(data).build();
    }
}
